package com.shuai.common.utils;

import cn.hutool.core.text.CharSequenceUtil;
import com.shuai.common.constant.EmailConstant;
import lombok.extern.slf4j.Slf4j;

import java.util.Random;

@Slf4j
public class EmailCodeUtils {


    private static final Random RANDOM = new Random();

    public static String generateCode() {
        StringBuilder code = new StringBuilder();
        for (int i = 0; i < EmailConstant.DIGIT; i++) {
            code.append(RANDOM.nextInt(10));
        }
        return code.toString();
    }

    public static boolean compare(String emailCode, String inputCode) {
        if (CharSequenceUtil.isBlank(emailCode) || inputCode.length() != EmailConstant.DIGIT) {
            return false;
        }
        return emailCode.equals(inputCode);
    }
}
